#ifndef _DUMP_PCI_CONFIGURE_SPACE_
#define _DUMP_PCI_CONFIGURE_SPACE_

#include "ReadOutPci.h"




VOID
DrawDumpPciConfigureSpaceBorder(
                                          VOID
                                          )
{

  UINT8  Index;
//  UINT16  Border;


  ST->ConOut->ClearScreen(ST->ConOut);
  
  ST->ConOut->SetAttribute(ST->ConOut,
                         EFI_YELLOW | EFI_BACKGROUND_BLUE
                         );

  ST->ConOut->ClearScreen(ST->ConOut);
     
  ST->ConOut->SetCursorPosition(ST->ConOut,
                                3,
                                0
                                );

  
  for(Index = 0; Index < 16; Index++ ){
    
    Print(L"%-02x ", Index);
      
    }
  
  ST->ConOut->SetCursorPosition(ST->ConOut,
                                0,
                                1
                                );
  
  for(Index = 0; Index < 16; Index++ ){    
    Print(L"%-02x  \n\r", Index);      
  }

  /*
  ST->ConOut->SetCursorPosition( ST->ConOut,
                                 0,
                                 0
                                 );
*/                                 

}



VOID
DrawDumpPciConfigureSpaceWordBorder(
                                                VOID
                                                )
{
  UINT8   Index;
  UINT16  Spacer;

  Spacer = 0;

  ST->ConOut->ClearScreen(ST->ConOut);

  ST->ConOut->SetAttribute(ST->ConOut,
                         EFI_YELLOW | EFI_BACKGROUND_BLUE
                         );

  ST->ConOut->ClearScreen(ST->ConOut);
     
  ST->ConOut->SetCursorPosition(ST->ConOut,
                                3,
                                0
                                );

  
  for(Index = 0; Index < 16; Index++ ){
    
    Print(L"%-02x", Index);

    Spacer++;
    if (Spacer == 2)
    { 
          Spacer = 0;
          Print(L"  ");
     }      
  }
  
  ST->ConOut->SetCursorPosition(ST->ConOut,
                                0,
                                1
                                );
  
  for(Index = 0; Index < 16; Index++ ){    
    Print(L"%-02x  \n\r", Index);      
 //Print(L"HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
    
  }  

}



VOID
DumpPciConfigureSpace (                     
                                UINT16   DeviceSelect,  
                                PCITable PciTable[]         
                      )
{
   UINT16  Index;
   UINT16  SpaceSize =256;
   UINT8   *TablePointer;
   UINT8   StartCol;
   UINT8   EndCol;
   UINT8   Col;
//   UINT8   EndRow;
   UINT8   Row;

   Row = 1;
   StartCol =  2;
   EndCol   = StartCol + 16;
   Col = StartCol;

   

  TablePointer = (UINT8*) (PciTable + DeviceSelect);

   DrawDumpPciConfigureSpaceBorder();


   ST->ConOut->EnableCursor(
                            ST->ConOut,
                            FALSE
                            );
   
  ST->ConOut->SetAttribute(ST->ConOut,
                            EFI_LIGHTGRAY| EFI_BACKGROUND_BLUE
                           );

//  ST->ConOut->ClearScreen(ST->ConOut);



  

  ST->ConOut->SetCursorPosition(ST->ConOut,
                                2,
                                1
                                );

  for(Index = 0; Index < SpaceSize; Index++){
    
     Print(L" %02x", *(TablePointer + Index) );
     Col++;
     if(Col >= EndCol){
       Col = StartCol;
       Row++;
       ST->ConOut->SetCursorPosition(ST->ConOut,
                                      StartCol,            
                                      Row      
       );
     }  
  }


   ST->ConOut->SetCursorPosition(ST->ConOut,
                                  0,            
                                  23      
   );


   Print(L"Bus =  %-02x  ", 
                         PciTable[DeviceSelect].Bus
                         );


   Print(L"Device =  %-02x  ", 
                         PciTable[DeviceSelect].Device
                         );
   

   Print(L"Func =  %-02x  \n\r", 
                         PciTable[DeviceSelect].Func
                         );



   
   Print(L"ESC = Exit    F1 = PCI Device List");










}





VOID
DumpPciConfigureSpaceWord(
                                   UINT16   DeviceSelect,  
                                   PCITable PciTable[]                            
                            )
{



 
                          

 // UINT32   Address;
 // UINT32   Value32;
  UINT16   *pValue;
  UINT16   Value16;
  UINT16   Index;
  UINT16   WordCount;
  UINT16   Spacer;
  UINT16   Col;
  UINT16   ColOffset;
  UINT16   Row;
  UINT16   RowOffset;

          
         Col = 0;
         ColOffset = 3;
         Row = 0;
         RowOffset = 1;
         Spacer = 0;
         WordCount = sizeof(PciTable)/sizeof(CHAR16);

         DrawDumpPciConfigureSpaceWordBorder();
                                            
    
         pValue = (UINT16*) ( PciTable + DeviceSelect );

          ST->ConOut->EnableCursor(
                           ST->ConOut,
                           FALSE
                           );
     
          ST->ConOut->SetAttribute(ST->ConOut,
                                    EFI_LIGHTGRAY| EFI_BACKGROUND_BLUE
                                   );


        
        ST->ConOut->SetCursorPosition(ST->ConOut,
                                      2,
                                      1
                                      );

          
  
        for(Index =0; Index < 128; Index++){

          Value16 = *(++pValue);

           Print(L"%-04x  ", *(pValue + Index ));
          Spacer++; 
          if(Spacer == 8){
               Spacer = 0;
               Row++;
               
                ST->ConOut->SetCursorPosition(ST->ConOut,
                                      ColOffset,
                                      Row + RowOffset
                                      );
             
          }  
        }  

         
  //       Value32 = Value32 << 16;
  //       Value32 = Value32 >> 16;

  //       Value16 = (UINT16) Value32;

  
 
  //  ST->ConOut->ClearScreen(ST->ConOut);
  
  
  
    
  
  
  
  
     ST->ConOut->SetCursorPosition(ST->ConOut,
                                    0,            
                                    23      
     );
  
  
     Print(L"Bus =  %-02x  ", 
                           PciTable[DeviceSelect].Bus
                           );
  
  
     Print(L"Device =  %-02x  ", 
                           PciTable[DeviceSelect].Device
                           );
     
  
     Print(L"Func =  %-02x  \n\r", 
                           PciTable[DeviceSelect].Func
                           );
  
  
  
     
     Print(L"ESC = Exit    F1 = PCI Device List");
  
  
  
  



};


#endif
